package com.zzsy.carosshopprojects.activitys.home.mainpage.barmanager.memberrecharge;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.adapter.ChoseActivityAdapter;
import com.zzsy.carosshopprojects.base.BaseFragment;
import com.zzsy.carosshopprojects.bean.ActivityBean;
import com.zzsy.carosshopprojects.view.refreshview.SpacesItemDecoration;

import java.util.ArrayList;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

public class CouponListFragment extends BaseFragment {
    public static CouponListFragment newInstance( ArrayList<ActivityBean> listData) {
        CouponListFragment couponListFragment = new CouponListFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("couponList", listData);
        couponListFragment.setArguments(bundle);
        return couponListFragment;
    }
    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    @BindView(R.id.tv_no_activity)
    TextView tvNoActivity;
    private ChoseActivityAdapter choseActivityAdapter;

    @Override
    protected int initLayout() {
        return R.layout.fg_activity;
    }

    @Override
    protected void initView(View view) {
        initTitle(view, getResources().getString(R.string.ActivityCouponList), getActivity());
        choseActivityAdapter = new ChoseActivityAdapter(getContext(), null, 0);
        choseActivityAdapter.setOnItemClickListener((v, position) -> {
            Bundle bundle = new Bundle();
            bundle.putSerializable("key", choseActivityAdapter.getListData().get(position));
            setFragmentResult(102, bundle);
            pop();
        });
        recycleView.setLayoutManager(new LinearLayoutManager(context));
        int space = ScreenAdapterTools.getInstance().loadCustomAttrValue(20);
        recycleView.addItemDecoration(new SpacesItemDecoration(space));
        recycleView.setAdapter(choseActivityAdapter);
        tvNoActivity.setOnClickListener(view1 -> {
            Bundle bundle = new Bundle();
            setFragmentResult(103, bundle);
            pop();
        });
    }

    @Override
    protected void initData(Context mContext) {
        ArrayList<ActivityBean> listData = (ArrayList<ActivityBean>) getArguments().getSerializable("couponList");
        if(listData != null){
            choseActivityAdapter.setListData(listData);
            choseActivityAdapter.notifyDataSetChanged();
        }
    }

    @Override
    protected void loadMethod() {

    }
}
